#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int a[N];
int mn[N][18], f[N];
void init_st() {
  f[1] = 0;
  rep(i, 2, n) f[i] = f[i >> 1] + 1;
  rep(i, 1, n) mn[i][0] = a[i];
  rep(j, 1, 16) {
    int len = 1 << j;
    rep(i, 1, n + 1 - len) mn[i][j] = min(mn[i][j - 1], mn[i + len / 2][j - 1]);
  }
}
int query(int l, int r) {
  int len = r + 1 - l;
  int k = f[len];
  len = 1 << k;
  return min(mn[l][k], mn[r + 1 - len][k]);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  init_st();
  while (m--) {
    int l, r;
    cin >> l >> r;
    cout << query(l, r) << ' ';
  }
  return 0;
}